package com.util;

/**
 * 个人所得税
 * IncomeTax.java
 * @author yaojinshan
 * @since 2018年6月20日上午10:04:38
 */
public class IncomeTax {
	static double[] taxSection = new double[]{0.0d,4500.0d,9000.0d,35000.0d};//税区间
	static double[] taxLevelSection = new double[]{0.0d,0.03d,0.1d,0.2d};
	
	
	public static void main(String[] args) {
		double income = 16440.0d;//收入
		double insurance = 1570.0d;//保险费
		double taxStartPoint = 5000.0d;//起征点
		computeRealIncome(income,insurance,taxStartPoint);
	}
	/**
	 * @param income 收入
	 * @param insurance 保险费用
	 * @param taxStartPoint 起征点
	 */
	public static void computeRealIncome(double income, double insurance,double taxStartPoint){
		double taxSalary = income - insurance - taxStartPoint;
		double tax = 0.0d;
		int taxLevel = 0; 
		//计算出 纳税区间 等级
		for(int i = 0 ; i < taxSection.length; i++){
			if(taxSalary <= taxSection[i]){
				taxLevel = i;
				break;
			}
		}
		while(taxLevel > 0){
			//本区间 纳税金额(当前纳税金额 - 上一区间的金额) * 本区间税率 
			tax += (taxSalary - taxSection[taxLevel - 1]) *  taxLevelSection[taxLevel];
			taxSalary = taxSection[taxLevel - 1];
			taxLevel--;
		}
		System.out.println("月工资：" + income + "元");
		System.out.println("五险一金费用："+ insurance + "元");
		System.out.println("起征点：" + taxStartPoint + "元");
		System.out.println("实际收入为：" + (income - insurance - tax) + "元");
		System.out.println("个人所得税为：" + tax + "元");
	}

}
